﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BoAddonBiz_FreightForwarder
{
    public class B1Form_SurveyForm : SAPBoAddon.B1Form
    {
        #region constructor
        public B1Form_SurveyForm()
        {
            this.frm_ItemEvent += new SAPBoAddon.IB1FormEvents.B1ItemEventEventHandler(B1Form_SurveyForm_frm_ItemEvent);
        }
        #endregion
        #region overload
        protected override bool BeforeSaveCheckFormData()
        {
            return true;
        }

        protected override void FormEditModeChange(SAPBoAddon.frmItemEditMode frmEditMode)
        {

        }

        protected override void FormInfoSetting(SAPBoAddon.B1FormSetting FormSetting)
        {
            this.FormSetting.FormType = B1FormTypes.ado_AVA_FF_SurveyList;
            this.FormSetting.FormFileName = "AVA_FF_SurveyForm.srf";
        }

        protected override void InitializeForm(SAPBoAddon.B1FormInitializePar InitPar)
        {

        }
        #endregion
        #region event
        void B1Form_SurveyForm_frm_ItemEvent(SAPBoAddon.B1AddonBase.B1ItemEvent pVal, ref bool BubbleEvent)
        {
            if (pVal.BeforeAction == false)
            {
                if (pVal.ItemUID == "Grid" && pVal.Row >= 0 && pVal.EventType == SAPbouiCOM.BoEventTypes.et_CLICK)
                {
                    SetParentSelectRow(CurrentForm, pVal.Row);
                }
                if (pVal.ItemUID == "Grid" && pVal.Row >= 0 && pVal.EventType == SAPbouiCOM.BoEventTypes.et_DOUBLE_CLICK)
                {
                    SAPbouiCOM.Form oForm = CurrentForm;
                    SetParentSelectRow(oForm, pVal.Row);
                    oForm.Close();
                    //SAPbouiCOM.Grid oGrid = CurrentForm.Items.Item("Grid").Specific;
                    //oGrid.Rows.SelectedRows.Clear();
                    //oGrid.Rows.SelectedRows.Add(pVal.Row);
                    //SAPbouiCOM.Form oParentForm = SBOApp.Forms.Item(CurrentForm.DataSources.UserDataSources.Item("ParentUID").Value);
                    //SAPbouiCOM.DBDataSource dbds = oParentForm.DataSources.DBDataSources.Item("@AVA_FF_BNO1");
                    //dbds.Offset = pVal.Row;
                    //CurrentForm.Close();
                }
            }
        }
        #endregion

        private void SetParentSelectRow(SAPbouiCOM.Form oForm,int row)
        {
            SAPbouiCOM.Grid oGrid = oForm.Items.Item("Grid").Specific;
            oGrid.Rows.SelectedRows.Clear();
            oGrid.Rows.SelectedRows.Add(row);
            SAPbouiCOM.Form oParentForm = SBOApp.Forms.Item(oForm.DataSources.UserDataSources.Item("ParentUID").Value);
            SAPbouiCOM.DBDataSource dbds = oParentForm.DataSources.DBDataSources.Item(oForm.DataSources.UserDataSources.Item("DataTable").Value);
            dbds.Offset = row;
        }
    }
}
